package com.ud.demobase.service;

import com.ud.demobase.dao.IUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService implements IUserService{

    //
    private static final  UserService userService = new UserService();
    public static UserService getInstance(){
        return userService;
    }

    private UserService(){};

    @Autowired
    private IUserDao userDao;




    public boolean login(String username, String password) {
        String pwd = userDao.getPasswordByUsername(username);
        return pwd != null && pwd.equals(password);
    }

    public void register(String username, String password) {
        if (userDao.userExists(username)) {
            throw new RuntimeException("用户名已存在");
        } else {
            userDao.addUser(username, password);
        }
    }
}
